package com.xnyzc.lhy.order.mapper.order;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xnyzc.lhy.order.entity.order.OaDOrder;
import com.xnyzc.lhy.order.entity.param.cms.PageDto;
import com.xnyzc.lhy.order.entity.user.message.OaSysMessage;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.*;

/**
 * <p>
 * 司机接单表 Mapper 接口
 * </p>
 *
 * @author lhy@xnyzc.com
 * @since 2019-07-31
 */
public interface OaDOrderMapper extends BaseMapper<OaDOrder> {

    List<OaDOrder> selectLockDriverList(@Param("driverId") String driverId, @Param("statusList") List<Integer> statusList);

    /**
     * 检索司机行程列表
     *
     * @param driverId
     * @return
     */
    List<Map<String, Object>> queryDriverOrder(@Param("driverId") Long driverId,@Param("orderStatus") Integer orderStatus, @Param("index") Long index, @Param("limit") Long limit);

    /**
     * 检索司机预约行程列表
     *
     * @param driverId
     * @return
     */
    List<Map<String, Object>> queryDriverBookingOrder(@Param("driverId") Long driverId, @Param("orderStatus") Integer orderStatus, @Param("index") Long index, @Param("limit") Long limit);

    /**
     * 查询订单状态
     */
    List<String> queryOrderStatus();

    /**
     * 获取行程详情
     *
     * @param orderNo
     * @return
     */
    Map<String, Object> queryOrderInfo(@Param("orderNo") String orderNo,@Param("appointmentTime") Date appointmentTime);

    /**
     * 获取行程轨迹
     */
    List<Map<String, Object>> queryOrderGps(@Param("orderNo") String orderNo);

    /**
     * 获取账单费用明细
     *
     * @param orderNo
     * @return
     */
    OaDOrder queryBillDetails(@Param("orderNo") String orderNo);

    /**
     * 获取账单补贴明细
     *
     * @param orderNo
     * @return
     */
    List<Map<String, Object>> queryBillSaltDetails(@Param("orderNo") String orderNo);

    /**
     * 获取车辆类型
     */
    String queryCarType(@Param("driverId") Long driverId);

    /**
     * 获取首页统计数据
     *
     * @param driverId 司机ID
     */
    List<Map<String, Object>> queryHomeDeatils(@Param("driverId") Long driverId);


    @Select("UPDATE \n" +
            "\toa_c_order_personal AS personal \n" +
            "LEFT JOIN oa_d_order AS driver \n" +
            "ON personal.order_no = driver.order_no \n" +
            "SET personal.driver_id=0,personal.order_status=#{personalOrderStatus},driver.order_status=#{driverOrderStatus} \n" +
            "WHERE personal.order_no=#{orderNo} AND personal.driver_id=#{driverId}")
    void throwMyBooingOrder(@Param("orderNo") String orderNo, @Param("driverId") Long driverId, @Param("personalOrderStatus") Integer personalOrderStatus, @Param("driverOrderStatus") Integer driverOrderStatus);

    @Select("SELECT * FROM oa_d_order WHERE driver_id=#{driverId} AND order_no=#{orderId} AND user_order_id=#{personalId} AND appointment_time = #{orderDate}")
    OaDOrder queryDriveCharterOrderById(@Param("driverId") Long driverId, @Param("orderId") String orderId, @Param("personalId") Long personalId,@Param("orderDate") Date orderDate);

    @Select("SELECT * FROM oa_d_order WHERE driver_id=#{driverId} AND order_no=#{orderId} AND user_order_id=#{personalId}")
    OaDOrder queryDriverOrderById(@Param("driverId") Long driverId, @Param("orderId") String orderId, @Param("personalId") Long personalId);


    @Select("UPDATE oa_d_order SET deleted=0,update_time=#{updateTime},order_status=#{orderStatus} " +
            "WHERE  driver_id=#{driverId} AND order_no=#{orderId} AND user_order_id=#{personalId}")
    void updateDriverOrderById(@Param("updateTime") Date updateTime, @Param("orderStatus") Integer orderStatus, @Param("driverId") Long driverId, @Param("orderId") String orderId, @Param("personalId") Long personalId);
}
